<template>
  <div class="rank" v-loading="topList.length === 0">
    <Scroll>
      <ul class="rank-inner">
        <li v-for="item in topList" :key="item.id" @click="select(item)">
          <div class="img-wrapper">
            <img :src="item.pic" alt="" />
          </div>
          <ul class="top">
            <li v-for="(s, index) in item.songList" :key="s.id">
              <span>{{ index + 1 }}.</span>
              <span>{{ s.songName + ' - ' + s.singerName }}</span>
            </li>
          </ul>
        </li>
      </ul>
    </Scroll>
  </div>
  <router-view v-slot="{ Component }">
    <transition appear name="slide">
      <component :is="Component" />
    </transition>
  </router-view>
</template>

<script>
import { ref } from 'vue'
import useRankData from './useRankData'
import Scroll from '@/components/Base/Scroll/Scroll'
import { setObj } from '@/assets/js/sessionStore'
export default {
  name: 'Rank',
  components: {
    Scroll
  },
  setup() {
    const topList = ref([])
    useRankData(topList)
    return {
      topList
    }
  },

  methods: {
    select({ id, name, period, pic }) {
      setObj('RANK_DETAIL', { id, name, period, pic })
      this.$router.push(`/rank/${id}`)
    }
  }
}
</script>

<style lang="scss" scoped>
.rank {
  height: 100%;
  .rank-inner {
    padding: 20px 0px;
    > li {
      display: flex;
      margin: 20px 20px 0;
      background: #fff;
      border-radius: 7px;
      &:nth-child(1) {
        margin-top: 0;
      }
      .img-wrapper {
        > img {
          width: 100px;
          height: 100px;
          border-top-left-radius: 7px;
          border-bottom-left-radius: 7px;
        }
      }
      .top {
        display: flex;
        flex-direction: column;
        justify-content: center;
        width: calc(100% - 100px);
        padding: 0 20px;
        > li {
          @include no-wrap;
          width: 100%;
          line-height: 26px;
          font-size: 12px;
        }
      }
    }
  }
}
</style>
